//
//  YAYIUserCommentCell.m
//  yayi
//
//  Created by Veer on 16/7/4.
//  Copyright © 2016年 Veer. All rights reserved.
//

#import "YAYIUserCommentCell.h"
#import "YAYIUserCommentModel.h"


@interface YAYIUserCommentCell()

@property (nonatomic, weak) UILabel *commentLbl;
@property (nonatomic, weak) UILabel *userNameLbl;
@property (nonatomic, weak) UILabel *timeLbl;
@property (nonatomic, weak) UILabel *numberLbl;

@property (nonatomic,strong) UIView *lineView;

@end

@implementation YAYIUserCommentCell


-(void)setModel:(YAYIUserCommentModel *)model
{
    _model = model;
    
    self.commentLbl.text = _model.words;
    self.userNameLbl.text = _model.username;
    
    NSDateFormatter *formater = [[NSDateFormatter  alloc] init];
    NSDate *date = [NSDate  dateWithTimeIntervalSince1970:[_model.createtime  floatValue] / 1000];
    formater.dateFormat = @"YYYY-MM-dd";
    NSString *dateString = [NSString stringWithFormat:@"%@",[formater stringFromDate:date]];
    self.timeLbl.text = dateString;
}


+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"YAYIUserCommentCell";
    
    YAYIUserCommentCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        cell = [[YAYIUserCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupSubView];
    }
    return self;
}


-(void)setupSubView
{
    UILabel *commentLbl = [UILabel new];
    commentLbl.numberOfLines = 0;
    commentLbl.textColor = [UIColor colorWithRed:122/255.0 green:120/255.0 blue:120/255.0 alpha:1];
    commentLbl.font = [UIFont systemFontOfSize:font13];
    [self.contentView addSubview:commentLbl];
    self.commentLbl = commentLbl;

    UILabel *userNameLbl = [UILabel new];
    userNameLbl.text = @"";
    userNameLbl.font = [UIFont systemFontOfSize:font10];
    userNameLbl.textColor = [UIColor lightGrayColor];
    [self.contentView  addSubview:userNameLbl];
    self.userNameLbl = userNameLbl;

    UILabel *numberLbl = [[UILabel alloc] init];
    numberLbl.textColor = [UIColor lightGrayColor];
    numberLbl.font = [UIFont systemFontOfSize:font10];
    [self.contentView addSubview:numberLbl];
    self.numberLbl = numberLbl;
    
    UILabel *timeLbl = [UILabel new];
    timeLbl.text = @"2016-02-06";
    timeLbl.textAlignment = NSTextAlignmentRight;
    timeLbl.textColor = [UIColor lightGrayColor];
    timeLbl.font = [UIFont systemFontOfSize:font10];
    [self.contentView addSubview:timeLbl];
    self.timeLbl = timeLbl;

    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = YAYICellLineColor;
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.commentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(10));
        make.top.equalTo(@(12));
        make.right.equalTo(@(-10));
    }];
    
    [self.userNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@34);
        make.top.mas_equalTo(self.commentLbl.mas_bottom).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 10));
    }];
    
    [self.numberLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userNameLbl.mas_right).with.offset(6);
        make.top.mas_equalTo(self.userNameLbl.mas_top);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];
    
    [self.timeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.commentLbl.mas_right).with.offset(-8);
        make.top.mas_equalTo(self.userNameLbl.mas_top);
        make.size.mas_equalTo(CGSizeMake(100, 10));
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(SCREEN_width);
    }];
}
@end
